import requests

# # 下载图片
# with open("./my_pic-1.jpg", "wb") as fp:
#     r = requests.get("https://imgm.gmw.cn/attachement/jpg/site215/20200203/7331387326140037126.jpg")
#     # 方法一
#     # fp.write(r.content)
#     # 方法二
#     for chunk in r.iter_content(512):
#         fp.write(chunk)


# 解压返回的HTML数据
# r = requests.get("https://www.163.com", stream=True)
# print(r.headers)
#
# print(r.raw.read())
# if r.headers['Content-Encoding'] == "gzip":
#     import gzip
#
#     # 数据解压
#     data = gzip.decompress(r.raw.read())
#     print(data)


# 压缩数据
import gzip

data = """
In case the JSON decoding fails, r.json() raises an exception. For example, if the response gets a 204 (No Content), or if the response contains invalid JSON, attempting r.json() raises ValueError: No JSON object could be decoded.

It should be noted that the success of the call to r.json() does not indicate the success of the response. Some servers may return a JSON object in a failed response (e.g. error details with HTTP 500). Such JSON will be decoded and returned. To check that a request is successful, use r.raise_for_status() or check r.status_code is what you expect.

Raw Response Content
In the rare case that you’d like to get the raw socket response from the server, you can access r.raw. If you want to do this, make sure you set stream=True in your initial request. Once you do, you can do this:
"""
compressed_data = gzip.compress(data.encode("utf-8"))

print(len(data))
print(len(compressed_data))



#www.163.com?name=zhangshan&name=lisi&name=wangwu